var express = require('express');
var router = express.Router();
var User = require('../database/user');

router.get('/', function(req, res, next) {  //访问router根目录时
  authentication(req, res);
  res.send('404 forbidden');   //返回一个提示字符串
});

router.get('/:user',function(req,res,next){  
  authentication(req, res);
  var user = req.session.user; 
   res.render('home');
});

function authentication(req, res) {
    if (!req.session.user) {
    	req.session.error="please login"
        return res.redirect('/login');
    }
};

module.exports = router;